package com.automannn.websocketmqtt.websocketNodeA.amqp.receiver;

import com.alibaba.fastjson.JSON;
import com.automannn.websocketmqtt.websocketNodeA.websocket.AutomannnWebSocketService;
import com.automannn.websoketmqtt.common.message.WsMessage;
import com.automannn.websoketmqtt.common.message.WsMessageQueueProperties;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.socket.TextMessage;

import java.io.IOException;
import java.util.Map;

/**
 * @author chenkh
 * @time 2020/10/13 15:18
 */
@Component
@RabbitListener(queues = WsMessageQueueProperties.TOPIC_FLAG+".nodeA")
public class WsMessageReceiver {

    @Autowired
    private AutomannnWebSocketService automannnWebSocketService;

    @RabbitHandler
    public void process(String str){
        System.out.println(str);
//        WsMessage wsMessage = (WsMessage) JSON.parse(str);
//        System.out.println(wsMessage.toString());
//        try {
//            automannnWebSocketService.sendMessage(wsMessage);
//        } catch (IOException e) {
//            //发送失败
//            e.printStackTrace();
//        }
    }
}
